package com.zjw.designPattern.listener.observer;

import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.Set;

/**
 * @description:
 * @author: zhangjiawei
 * @createTime:2022/3/9 16:41
 * @modified by:
 */
@Component
public class EventHandle {

  //  @Resource
    Set<ObserverListener> handlers;

    public EventHandle(Set<ObserverListener> handlers) {
        this.handlers = handlers;
    }

    public void publish(CommonPushMsg.Action action, Collection<? extends FundOffer> offers, FundOffer old) throws Exception {
        FundOfferEvent event = FundOfferEvent.builder()
                .action(action)
                .offers(offers)
                .oldOffer(old)
                .build();
        for (ObserverListener handler : handlers) {
            handler.onFundOfferEvent(event, 0, false);
        }
    }
}
